package com.sskj.b70.v.activity;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.sskj.b70.R;
import com.sskj.b70.adapter.MyFragmentPagerAdapter;
import com.sskj.b70.common.App;
import com.sskj.b70.m.bean.TabEntity;
import com.sskj.b70.p.activity.DagListPresenter;
import com.sskj.b70.v.base.BaseActivity;
import com.sskj.b70.v.fragment.DagListFragment;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-08 09:56
 */
public class DagListActivity extends BaseActivity<DagListPresenter> {
    @BindView(R.id.commonTabLayout)
    CommonTabLayout commonTabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    private String[] mTitles = {App.INSTANCE.getString(R.string.dag_list_first_title), App.INSTANCE.getString(R.string.dag_list_second_title)};
    private ArrayList<Fragment> mFragments;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_dag_list;
    }

    @Override
    public DagListPresenter getPresenter() {
        return new DagListPresenter();
    }

    @Override
    protected void initView() {
        mFragments = new ArrayList<>();
        mFragments.add(DagListFragment.newInstance(1));
        mFragments.add(DagListFragment.newInstance(0));


        ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
        for (int i = 0; i < mTitles.length; i++) {
            mTabEntities.add(new TabEntity(mTitles[i]));
        }
        commonTabLayout.setTabData(mTabEntities);

        commonTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                viewPager.setCurrentItem(position, true);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(), mFragments));

        viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                commonTabLayout.setCurrentTab(position);
            }
        });

    }

}
